library(openxlsx)
folder='data'
fileName='dataMunicipalidades.xlsx'
fileToRead=file.path(folder,fileName)
Informacion=read.xlsx(fileToRead, sheet = 1)
Servicios=read.xlsx(fileToRead, sheet = 2)
Participacion=read.xlsx(fileToRead, sheet = 3)
names(Informacion)
## [1] "Las.celdas.en.blanco.deber<U+00E1>n.llenarse.con.la.URL.(http://www.munisanmiguel.gob.pe/).de.la.p<U+00E1>gina.del.ayuntamiento.donde.se.observ<U+00F3>.el.cumplimiento.de.los.requisitos.del.nivel..Esta.URL.ser<U+00E1>.utilizada.por.el.docente.para.verificar.la.fiabilidad.de.los.datos.recopilados..Las.celdas.sombreadas.en.azul.se.llenan.autom<U+00E1>ticamente."
## [2] "X2"                                                                                                                                                                                                                                                                                                                                                             
## [3] "X3"                                                                                                                                                                                                                                                                                                                                                             
## [4] "X4"                                                                                                                                                                                                                                                                                                                                                             
## [5] "X5"                                                                                                                                                                                                                                                                                                                                                             
## [6] "X6"
Informacion=Informacion[-c(2:5)]
names(Servicios)
## [1] "Las.celdas.en.blanco.deber<U+00E1>n.llenarse.con.la.URL.(http://www.munisanmiguel.gob.pe/).de.la.p<U+00E1>gina.del.ayuntamiento.donde.se.observ<U+00F3>.el.cumplimiento.de.los.requisitos.del.nivel..Esta.URL.ser<U+00E1>.utilizada.por.el.docente.para.verificar.la.fiabilidad.de.los.datos.recopilados..Las.celdas.sombreadas.en.azul.se.llenan.autom<U+00E1>ticamente."
## [2] "X2"                                                                                                                                                                                                                                                                                                                                                             
## [3] "X3"                                                                                                                                                                                                                                                                                                                                                             
## [4] "X4"                                                                                                                                                                                                                                                                                                                                                             
## [5] "X5"                                                                                                                                                                                                                                                                                                                                                             
## [6] "X6"                                                                                                                                                                                                                                                                                                                                                             
## [7] "X7"                                                                                                                                                                                                                                                                                                                                                             
## [8] "X8"
Servicios=Servicios[,c(1,6)]
names(Participacion)
## [1] "Las.celdas.en.blanco.deber<U+00E1>n.llenarse.con.la.URL.(http://www.munisanmiguel.gob.pe/).de.la.p<U+00E1>gina.del.ayuntamiento.donde.se.observ<U+00F3>.el.cumplimiento.de.los.requisitos.del.nivel..Esta.URL.ser<U+00E1>.utilizada.por.el.docente.para.verificar.la.fiabilidad.de.los.datos.recopilados..Las.celdas.sombreadas.en.azul.se.llenan.autom<U+00E1>ticamente."
## [2] "X2"                                                                                                                                                                                                                                                                                                                                                             
## [3] "X3"                                                                                                                                                                                                                                                                                                                                                             
## [4] "X4"                                                                                                                                                                                                                                                                                                                                                             
## [5] "X5"                                                                                                                                                                                                                                                                                                                                                             
## [6] "X6"
Participacion=Participacion[,c(1,6)]
Informacion=Informacion[-c(1),]
Participacion=Participacion[-c(1),]
Servicios=Servicios[-c(1),]
Informacion=Informacion[-c(43:310),]
Participacion=Participacion[-c(43:313),]
Servicios=Servicios[-c(43:311),]
colnames(Informacion) = c("nombre","X6")
colnames(Participacion) = c("nombre","X6")
colnames(Servicios) = c("nombre","X6")
row.names(Informacion)=NULL
row.names(Participacion)=NULL
row.names(Servicios)=NULL
Informacion[2,"nombre"] = "Jesus Maria"
Informacion[7,"nombre"] = "Ancon"
Informacion[12,"nombre"] = "Villa Maria del Triunfo"
Informacion[20,"nombre"] = "Santa Maria del Mar"
Informacion[29,"nombre"] = "Pachacamac"
Informacion[30,"nombre"] = "Lurin"
Informacion[31,"nombre"] = "Rimac"
Informacion[37,"nombre"] = "Brena"
Participacion[2,"nombre"] = "Jesus Maria"
Participacion[7,"nombre"] = "Ancon"
Participacion[12,"nombre"] = "Villa Maria del Triunfo"
Participacion[20,"nombre"] = "Santa Maria del Mar"
Participacion[29,"nombre"] = "Pachacamac"
Participacion[30,"nombre"] = "Lurin"
Participacion[31,"nombre"] = "Rimac"
Participacion[37,"nombre"] = "Brena"
Servicios[2,"nombre"] = "Jesus Maria"
Servicios[7,"nombre"] = "Ancon"
Servicios[12,"nombre"] = "Villa Maria del Triunfo"
Servicios[20,"nombre"] = "Santa Maria del Mar"
Servicios[29,"nombre"] = "Pachacamac"
Servicios[30,"nombre"] = "Lurin"
Servicios[31,"nombre"] = "Rimac"
Servicios[37,"nombre"] = "Brena"
datafinal=merge(Informacion,Servicios, by = "nombre")
dataMuniFinal=merge(datafinal,Participacion, by = "nombre")
colnames(dataMuniFinal) =c("Nombre", "Informacion", "Servicios", "Participacion")
str(dataMuniFinal)
## 'data.frame':    42 obs. of  4 variables:
##  $ Nombre       : chr  "Ancon" "Ate" "Barranco" "Brena" ...
##  $ Informacion  : chr  "0" "4" "2" "2" ...
##  $ Servicios    : chr  "0" "2" "2" "2" ...
##  $ Participacion: chr  "0" "2" "2" "2" ...
dataMuniFinal[c(2:4)] = lapply(dataMuniFinal[c(2:4)], as.numeric)
str(dataMuniFinal)
## 'data.frame':    42 obs. of  4 variables:
##  $ Nombre       : chr  "Ancon" "Ate" "Barranco" "Brena" ...
##  $ Informacion  : num  0 4 2 2 0 2 3 0 3 3 ...
##  $ Servicios    : num  0 2 2 2 0 2 1 0 1 1 ...
##  $ Participacion: num  0 2 2 2 0 2 0 0 2 2 ...
library(tidyverse)
## -- Attaching packages --------------------------------------------------------------------------------- tidyverse 1.2.1 --
## <U+221A> ggplot2 3.1.0     <U+221A> purrr   0.2.5
## <U+221A> tibble  1.4.2     <U+221A> dplyr   0.7.5
## <U+221A> tidyr   0.8.1     <U+221A> stringr 1.3.1
## <U+221A> readr   1.1.1     <U+221A> forcats 0.3.0
## -- Conflicts ------------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
dataMuniFinal = dataMuniFinal[-c(1,5,8),]
#Importando data final con el codigo por Municipio
dataMuniCod = read.csv("dataMuniFinal.csv")
dataMuniCod=dataMuniCod[,-c(1)]
names(dataMuniCod)
## [1] "Nombre"        "Informacion"   "Servicios"     "Participacion"
## [5] "Codigo"
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
p <- plot_ly(
    type = 'scatterpolar',
    fill = 'toself'
  ) %>%
  add_trace(
    r = dataMuniCod$Informacion,
    theta = dataMuniCod$Codigo,
    name = 'Informacion'
  ) %>%
  add_trace(
    r = dataMuniCod$Servicios,
    theta = dataMuniCod$Codigo,
    name = 'Servicios'
  ) %>%
  add_trace(
    r = dataMuniCod$Participacion,
    theta = dataMuniCod$Codigo,
    name = 'Participacion'
  ) %>%
  layout(
    polar = list(
      radialaxis = list(
        visible = T,
        range = c(0,4)
      )
    )
  )

p
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode
## No scatterpolar mode specifed:
##   Setting the mode to markers
##   Read more about this attribute -> https://plot.ly/r/reference/#scatter-mode